<template>
  <div class="containercontent equipStadndar">
    <div class="selectw100 seachTip" style="height:68px">
      <div class="inlineblock searchInput">
        <el-input v-model="searchName" size="mini" placeholder="仪器类型" @keyup.enter.native="readEquipmentType"></el-input>
      </div>
      <div class="inlineblock searchIcon">
         <el-button size="mini" @click="readEquipmentType">搜索</el-button>
        <el-button size="mini" @click="emptySearch">清空</el-button>
      </div>
    </div>
    <div style="height:calc(100% - 68px)">
      <div style="width:calc(100%/3);height:100%;" class="inlineblock">
        <div class="separaterow">
          <div class="tableTittle">
            <div><span class="fontImpact">1</span><span>仪器类型</span></div>
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="addEquipType('new')" style="float:right" v-if="userOpernation.add.display">添加仪器类型</el-button>
          </div>
          <el-table :data="mainEquipType" style="width: 100%" class="tableCon" size="mini" highlight-current-row @cell-click="showEquipType">
            <el-table-column label="序号" fixed min-width="45px">
              <template slot-scope="scope">
                {{scope.$index+1}}
              </template>
            </el-table-column>
            <el-table-column property="name" label="类型" fixed min-width="90px" show-overflow-tooltip>
            </el-table-column>
            <!--doMain-->
            <el-table-column property="doMain" label="主辅仪器" v-if="false" min-width="90px" :formatter="mainFormatter">
            </el-table-column>
            <el-table-column property="status" label="状态" width="80px" :formatter="formatter">
            </el-table-column>
            <el-table-column label="操作" min-width="150px">
              <template slot-scope="scope">
                <el-button v-if="scope.row.status=='1' && userOpernation.disable.display" type="text" size="mini" @click="isStart(scope.row,'perent')">停用</el-button>
                <el-button v-if="scope.row.status=='0' && userOpernation.enable.display" type="text" size="mini" @click="isStart(scope.row,'perent')">启用</el-button>
                <!--isApprove-->
                <el-button v-if="scope.row.isApprove" type="text" size="mini" @click="reviewFlowPop(scope.row,'parent')">审核</el-button>
                <el-button @click="editEquipType(scope.row,'edit')" v-if="(scope.row.status =='2' || scope.row.status =='4') && userOpernation.update.display"
                  type="text" size="mini" :disabled="scope.row.source !='' && scope.row.source != undefined ">编辑</el-button>
                <el-button @click="editEquipType(scope.row,'look')" v-if="userOpernation.select.display " type="text" size="mini">详情</el-button>


                <el-button type="text" size="mini" v-if=" userOpernation.delete.display" @click="deleteEquipType(scope.row,'parent')" :disabled="(scope.row.source !='' && scope.row.source != undefined ) || scope.row.status == 3">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div style="width:calc(66% - 20px);vertical-align:top;height:100%;margin-left:20px;" class="inlineblock">
        <div v-if="eqtypeShow" style="height:100%;">
          <div class="inlineblock" style="width: 49%;height:100%;">
            <div class="separaterow">
              <div class="tableTittle">
                <div><span class="fontImpact">2</span><span>仪器类别</span></div>
                <el-button type="primary" icon="el-icon-plus" size="mini" style="float:right" @click="addEquipType('newChild')" v-if="userOpernation.add.display">添加仪器类别</el-button>
              </div>
              <el-table :data="mainEquipName" size="mini" style="width: 100%;" class="tableCon" highlight-current-row @cell-click="showCheckTenance"
                v-if="reload">
                <el-table-column label="序号" fixed min-width="45px">
                  <template slot-scope="scope">
                    {{scope.$index+1}}
                  </template>
                </el-table-column>
                <el-table-column property="name" label="类别" fixed min-width="90px" show-overflow-tooltip>
                </el-table-column>
                <el-table-column property="status" label="状态" width="80px" :formatter="formatter">
                </el-table-column>
                <el-table-column label="操作" min-width="150px">
                  <template slot-scope="scope">
                    <el-button v-if="scope.row.status=='1' && userOpernation.disable.display " type="text" size="mini" @click="isStart(scope.row,'child')">停用</el-button>
                    <el-button v-if="scope.row.status=='0'  && userOpernation.enable.display" type="text" size="mini" @click="isStart(scope.row,'child')">启用</el-button>
                    <el-button v-if="scope.row.isApprove" type="text" size="mini" @click="reviewFlowPop(scope.row,'child')">审核</el-button>
                    <el-button @click="editEquipType(scope.row,'editChild')" v-if="(scope.row.status =='2' || scope.row.status =='4')  && userOpernation.update.display"
                      type="text" size="mini" :disabled="scope.row.source !='' && scope.row.source != undefined ">编辑</el-button>
                    <el-button @click="editEquipType(scope.row,'lookChild')" v-if="userOpernation.select.display " type="text" size="mini">详情</el-button>

                    <el-button type="text" size="mini" v-if="userOpernation.delete.display " @click="deleteEquipType(scope.row,'child')" :disabled="(scope.row.source !='' && scope.row.source != undefined) || scope.row.status == 3">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>

          </div>
          <div style="height:100%;width:calc(50% - 20px);vertical-align:top;margin-left:20px;" class="inlineblock">
            <div v-if="eqDetailShow" style="height:100%;" class="tabChange">
              <!--<instrument-detail :eqType="eqType" :eqEditOrNew="eqEditOrNew" :detailType="eqDetailShowType"></instrument-detail>-->
              <div style="height:100%;padding-top: 0;" class="separaterow">

                <div class="tableTittle inlineblock" style="width:100%;">
                  <div><span class="fontImpact">3</span><span>检查维护</span></div>

                  <!--<el-button type="primary" icon="el-icon-plus" size="mini"  style="float:right">添加仪器名称</el-button>-->
                </div>



                <div style="width:164px;margin:auto">
                  <div :class="{'tabName':true,'activeTab':nowTab=='maintainRecord'}" v-on:click="nowTab='maintainRecord'" style="margin-right:-4px;">
                    保养项
                  </div>
                  <div :class="{'tabName':true,'activeTab':nowTab=='useCheck'}" v-on:click="nowTab='useCheck'">
                    检查项
                  </div>
                </div>
                <div style="height:calc(100% - 90px);">
                  <!-- 维护记录 -->
                  <div v-if="nowTab=='maintainRecord'" style="height:100%;position:relative;">
                    <!--<div class="penalrow selectw100" style="height: 30px;">-->
                    <!--保养项-->
                    <div class="basicRightDistanceA">
                      <el-button type="primary" size="mini" icon="el-icon-plus" @click="addcheck('tenance')" v-if="userOpernation.add.display">添加保养项</el-button>
                    </div>
                    <!--</div>-->

                    <div class="childTable">
                      <el-table :data="maintainRecordTableDate" style="width: 100%;height:100%;" class="tableCon" size="mini" key="maintainRecordTableDate"
                        ref="standardTable">
                        <el-table-column label="序号" min-width="50px">
                          <template slot-scope="scope">
                            {{scope.$index+1}}
                          </template>
                        </el-table-column>
                        <el-table-column property="content" label="保养项" :show-overflow-tooltip="true" min-width="100px">
                        </el-table-column>
                        <el-table-column label="操作" min-width="120px">
                          <template slot-scope="scope">
                            <el-button type="text" size="mini" @click="editCheck(scope.row,'tenance')" v-if="userOpernation.select.display">详情</el-button>
                            <el-button type="text" size="mini" @click="deleteEquipType(scope.row,'tenance')" v-if="userOpernation.delete.display">删除</el-button>
                          </template>
                        </el-table-column>
                      </el-table>
                    </div>
                  </div>
                  <!-- 检查项 -->
                  <div v-if="nowTab=='useCheck'" style="height:100%;position:relative;">
                    <!--检查项-->
                    <div class="basicRightDistanceA">
                      <el-button type="primary" size="mini" icon="el-icon-plus" @click="addcheck('check')" v-if="userOpernation.add.display">添加检查项</el-button>
                    </div>
                    <div class="childTable">
                      <el-table :data="checkList" style="width: 100%;height:100%;" size="mini" class="tableCon" key="userCheck" ref="userCheck">
                        <el-table-column label="序号" min-width="50px">
                          <template slot-scope="scope">
                            {{scope.$index+1}}
                          </template>
                        </el-table-column>
                        <el-table-column property="content" label="检查项" :show-overflow-tooltip="true" min-width="100px">
                        </el-table-column>
                        <el-table-column label="操作" min-width="120px">
                          <template slot-scope="scope">
                            <el-button type="text" size="mini" @click="editCheck(scope.row,'check')" v-if="userOpernation.select.display">详情</el-button>
                            <el-button type="text" size="mini" @click="deleteEquipType(scope.row,'check')" v-if="userOpernation.delete.display">删除</el-button>
                          </template>
                        </el-table-column>
                      </el-table>
                    </div>
                  </div>
                </div>

              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <el-dialog :visible.sync="addVisible" width="55%" :show-close='false' :closeOnClickModal='false' class="equipTypeForm equipDialog">
      <span slot="title" class="dialog-title">
		  		{{newOrEdit=='new' || newOrEdit=='newChild' ? '新增':(newOrEdit=='look' || newOrEdit=='lookChild'?'查看':'编辑')}}仪器{{newOrEdit == "new" || newOrEdit == "edit" || newOrEdit == "look"?'类型':'类别'}}
			    <el-button @click="close('equipTypeForm')" size="mini" class="popupClose">关闭</el-button>
			  </span>
      <el-form label-width="110px" :inline="false" class="demo-form-inline " :model="equipTypeForm" :rules="equipTypeRules" ref="equipTypeForm">
        <el-form-item label="仪器类型" prop='name' v-if="newOrEdit == 'new' || newOrEdit == 'edit'">
          <el-col :span="22">
            <el-input size="mini" placeholder="仪器类型" v-model="equipTypeForm.name"></el-input>
          </el-col>
        </el-form-item>
        <!--为二级类型的添加或者编辑时带出一级类型的仪器类型和主辅仪器-->
        <el-form-item label="仪器类型" v-if="newOrEdit != 'new' && newOrEdit != 'edit'">
          <el-col :span="22">
            <el-input size="mini" placeholder="仪器类型" v-model="checkRow.name" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="仪器类别" prop='name' v-if="newOrEdit != 'new' && newOrEdit != 'edit' && newOrEdit != 'look'">
          <el-col :span="22">
            <el-input size="mini" placeholder="仪器类别" v-model="equipTypeForm.name" :disabled="newOrEdit == 'lookChild'"></el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <el-tabs style="height:calc(100% - 80px)">
        <el-tab-pane label="审核信息" style="height:100%;" v-if="(newOrEdit == 'look' || newOrEdit == 'lookChild') && (equipTypeForm.source == '' || equipTypeForm.source == null || equipTypeForm.source == undefined )">
          <div style="height:100%">
            <div id="myIframe" v-loading="loading1" v-if = "reloadReview" style = "text-align:center;">
               <span style = "color:#909399;line-height:100px;" v-if = "WorkFlowMsg != '' && WorkFlowMsg != undefined" >{{WorkFlowMsg}}</span>
              <iframe :src="url" id="workFlowIframe" ref="workFlowIframe" width="100%" height="100%" frameborder="0" scrolling="auto"></iframe>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>

      <span slot="footer" class="dialog-footer" v-if="newOrEdit !='look' && newOrEdit !='lookChild'">
          <el-button type="primary"  size="mini" @click="subEquipType('commit')" :disabled = "!isRepeat">提交</el-button>
			    <!--<el-button type="primary" @click="subEquipType('save')" v-if="isStatus == '2' || newOrEdit == 'new' || newOrEdit == 'newChild'" size="mini" :disabled = "!isRepeat">保存</el-button>-->
			    <el-button  size="mini" @click="close('equipTypeForm')">取 消</el-button>
			  </span>
    </el-dialog>
    <el-dialog :visible.sync="checkItemVisible" width="55%" :show-close='false' :closeOnClickModal='false' class="equipTypeForm">

      <span slot="title" class="dialog-title">
            {{lookOrNew}}{{nowTab =='maintainRecord'?'保养项':'检查项'}}
            <el-button @click="closeCheck('checkForm')" size="mini" class="popupClose">关闭</el-button>
          </span>
      <el-form label-width="110px" :inline="false" class="demo-form-inline" :model="checkForm" :rules="checkRules" ref="checkForm">
        <el-form-item label="仪器类别">
          <el-col :span="22">
            <el-input size="mini" placeholder="仪器类别" v-model="checkChildRow.name" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="类型" prop='checkType' v-if="nowTab =='maintainRecord'">
          <el-col :span="22">
            <el-select v-model="checkForm.checkType" placeholder="请选择" size="mini" disabled>
              <el-option v-for="item in maintenanceSelect.itemList" :key="item.code" :label="item.name" :value="item.code">
              </el-option>
            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item label="类型" prop='checkType1' v-if="nowTab =='useCheck'">
          <el-col :span="22">
            <el-select v-model="checkForm.checkType1" placeholder="请选择" size="mini" :disabled="!canEdit">
              <el-option v-for="item in mainTenance" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item label="保养项" prop='content' v-if="nowTab =='maintainRecord'">
          <el-col :span="22">
            <el-input size="mini" placeholder="保养项" v-model="checkForm.content" :disabled="!canEdit"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="检查项" prop='content' v-if="nowTab =='useCheck'">
          <el-col :span="22">
            <el-input size="mini" placeholder="检查项" v-model="checkForm.content" :disabled="!canEdit"></el-input>
          </el-col>
        </el-form-item>
        <!--<el-form-item label="名称" prop='name'>
              <el-col :span="22">
                <el-input size="mini" placeholder="名称" v-model="checkForm.name" :disabled="!canEdit"></el-input>
              </el-col>
            </el-form-item>-->

      </el-form>
      <span slot="footer" class="dialog-footer" v-if="lookOrNew == '新增'">
            <!--<el-button type="primary" v-if="isStatus == '2'" size="mini" @click="changeStatus(scope.row)">提交</el-button>-->
            <el-button type="primary" @click="subCheck" size="mini" :disabled = "!isRepeat">保存</el-button>
            <el-button  size="mini" @click="closeCheck('checkForm')">取 消</el-button>
          </span>
      <!--查看-->
      <div slot="footer" class="user-footer" v-if="lookOrNew == '查看'" style="height:35px;line-height:35px;">
        <span>
              创建人:{{checkForm.createBy}} 
            </span>
        <span>
              创建时间:{{checkForm.createTime}} 
            </span>
        <span v-if="checkForm.updateBy != undefined">
              修改人：{{checkForm.updateBy}} 
            </span>
        <span v-if="checkForm.updateTime != undefined">
              修改时间：{{checkForm.updateTime}} 
            </span>
      </div>
    </el-dialog>
    <review-flow :addVisible.sync="reviewFlowShow" :reviewData="reviewData" :procInstType="procInstType" :reviewTitle="reviewTitle"
      @reloadMain="closeRefresh"></review-flow>

  </div>
</template>

<script>
  import { mapState } from 'vuex'
  const reviewFlow = () =>
		import('../../../common/reviewFlow.vue');

  export default {
    data() {
      let that = this;
      return {
        searchName: '',
        mainEquipType: [],
        addVisible: false,
        equipTypeForm: {
          name: '',
          status: 2,
          doMain: '',
        },
        newOrEdit: '',
        equipTypeRules: {
          name: [
            { required: true, type: 'string', message: '请填写仪器类型', trigger: 'blur' },
          ],
        },
        isStatus: '',
        rowId: '',
        checkRow: {},
        checkChildRow: {},
        childRowId: '',
        reload: false,
        nowTab: 'maintainRecord',
        maintainRecordTableDate: [], //保养项
        checkList: [], //检查项
        checkItemVisible: false, //添加检查项
        checkForm: {
          checkType: "MA01", //数据字典
          checkType1: '',
        },
        checkRules: {
          content: [
            { required: true, type: 'string', message: '请填写内容', trigger: 'blur' },
          ],
          checkType1: [
            { required: true, message: '请选择类型', trigger: 'change' },
          ],
        },
        checkStatus: 'tenance',//是维护项还是使用检查项的弹框
        lookOrNew: '新增',
        canEdit: true,
        eqDetailShow: false,
        eqtypeShow: false,
        isRepeat: true,
        reloadReview:false,
        WorkFlowMsg:"",

        addNameShow: false,
        reviewFlowShow: false, //审核流显示
        reviewData: null, //点击行需要审核的信息
        procInstType: 't_equipment_type', //审核流要查的表
        reviewTitle: '仪器审核',
        parentOrChild: 'parent',
        url: "",
        loading1: true,
      }
    },
    computed: {
      ...mapState(['daibanItemShow', 'enableStatus', 'isMainEquip', 'maintenanceSelect', 'mainTenance', 'submitType', 'daibanItem']),
    },
    created() {
      let that = this;
      if (this.daibanItemShow) {
        let daibanRow = Object.assign({}, this.daibanItem)
        if (this.daibanItem.level == 1) {
          setTimeout(() => {
            that.reviewFlowPop(daibanRow, 'parent')
          }, 0)
        } else {
          setTimeout(() => {
            that.reviewFlowPop(daibanRow, 'child')
          }, 0)

        }
        this.$store.commit('passDaibanItemShow', false)
      }

    },
    mounted() {
      this.readEquipmentType();
      this.$store.dispatch('dogetDictionary')

    },

    props: ['userOpernation'],
    watch: {
      daibanItem(newer, older) {
        if (this.daibanItemShow) {
          if (this.daibanItem.level == 1) {
            this.reviewFlowPop(this.daibanItem, 'parent')
          } else {
            this.reviewFlowPop(this.daibanItem, 'child')
          }
          this.$store.commit('passDaibanItemShow', false)
        }
      },
    },
    components: {
      reviewFlow
    },
    methods: {
      emptySearch() {
        this.searchName = '';
        this.readEquipmentType();
      },
      // 过滤状态
      formatter(row, column, cellValue, index) {
        return this.util.changeStatus({ cellValue: cellValue, list: this.enableStatus })

      },
      // 过滤仪器
      mainFormatter(row, column) {
        if (row.doMain) {
          var newDoMain = '主仪器'
        } else {
          var newDoMain = '辅仪器'
        }
        return newDoMain;
      },
      //读取一级列表
      readEquipmentType(parp) {
        this.rowId = '';
        var params = {
          name: this.searchName,
        }
        this.$http({
          method: 'post',
          apiUrl: '/technology/readEquipmentTypeList.htm',
          params: params,
          isJson: false,
        }).then(res => {
          if (res.code == 0) {
            this.mainEquipType = res.data;
            this.mainEquipName = [];
            this.maintainRecordTableDate = [];
            this.checkList = [];

          }

        })
      },
      // 审核流弹框
      reviewFlowPop(row, parentOrChild) {
        this.reviewFlowShow = true;
        this.reviewData = row;
        this.parentOrChild = parentOrChild;
      },
      // 刷新页面
      closeRefresh() {
        this.$store.dispatch('getWorkflowList', 0).then(res => {
                this.$notify({
                    showClose: true,
                    message: '操作成功',
                    type: 'success',
                    title:"成功"
                })
            })
        if (this.parentOrChild == "parent") {// 如果是仪器类型  刷新左边的列表
          this.readEquipmentType();
        } else {
          this.showEquipType({ id: this.rowId }, { label: '类型' })
          this.childRowId = ''
        }
      },
      // 点击一级列表显示二级仪器类型
      showEquipType(row, column, cell, event) {
        for (var i in row) {
          this.checkRow[i] = row[i]
        }
        this.rowId = row.id;
        // if (column.label != '操作') {
          var data = {
            id: row.id,
          }
          this.$http({
            method: 'post',
            apiUrl: '/technology/readEquipmentTypeListById.htm',
            params: data,
            isJson: false,
          }).then(res => {
            if (res.code === 0) {

              this.mainEquipName = res.data;
              this.eqtypeShow = true;
              this.reLoad()
              this.childRowId = '';
              this.maintainRecordTableDate = [];
              this.checkList = [];
            }

          })
        // }

      },
      // 是否重加载
      reLoad() {
        this.reload = false;
        this.$nextTick(() => {
          //dom元素更新后执行，此时能拿到p元素的属性
          // this.message = this.$refs.myWidth.offsetWidth;
          this.reload = true;
        })
      },
      //添加仪器类型
      addEquipType(newOrEdit) {
        this.newOrEdit = newOrEdit;
        if (newOrEdit == 'newChild') {
          if (this.rowId == '') {
            this.$message({
              type: 'info',
              message: '请先选中仪器类型！'
            })
          } else {
            this.addVisible = true;
          }
        } else {
          this.addVisible = true;
        }



      },
      // 编辑仪器类型
      editEquipType(row, editOrLook) {
        this.newOrEdit = editOrLook
        this.addVisible = true;
        for (var i in row) {
          this.equipTypeForm[i] = row[i];
        }
        this.isStatus = this.equipTypeForm.status;
        if (editOrLook == "look" || editOrLook == "lookChild") {
          this.reloadReview = true;
          if (process.env.NODE_ENV == 'development') {
            this.url = "../../static/workflow.html?id=" + this.equipTypeForm.id + "&procInstType=" + this.procInstType + "&fromModel=look"
          } else {
            this.url = "static/workflow.html?id=" + this.equipTypeForm.id + "&procInstType=" + this.procInstType + "&fromModel=look"

          }
          var that = this;
          // setTimeout(function () {
          //   let iframe = document.getElementById("workFlowIframe");
            window.addEventListener('message', that.handleMessage)
          // }, 3000)
        }
      },
      handleMessage(event) {
        const data = event.data
        switch (data.cmd) {
          case 'loadingHide':
            this.loading1 = false;
            this.WorkFlowMsg = "";
            break;
          case 'errorMsg': 
            this.loading1 = false;
            this.WorkFlowMsg = "没有查询到审核信息"
            break;  
        }
      },
      close(formName) {
        this.$refs[formName].resetFields();
        this.addVisible = false;
        this.isRepeat = true;
        this.equipTypeForm = {
          name: "",
          status: 2,
          doMain: '',
        };
        this.parentOrChild = "parent"
        this.loading1 = true;
        this.reloadReview = false;
        this.WorkFlowMsg = "";
      },
      // 提交添加仪器类型
      subEquipType(value) {
        this.$refs.equipTypeForm.validate((valid) => { //表单验证
          if (valid) {
            if (this.newOrEdit == 'new') {
              var url = '/technology/addEquipmentType.htm';
              var data = {
                name: this.equipTypeForm.name,
                level: 1,
                doMain: true,
              };
              if (value == 'commit') {
                data.submitType = this.submitType.submitOpen
              } else if (value == 'save') {
                data.submitType = this.submitType.submitDraft
              }
            } else if (this.newOrEdit == 'edit' || this.newOrEdit == 'editChild') {
              var url = '/technology/updateEquipmentType.htm';
              var data = {
                id: this.equipTypeForm.id,
                name: this.equipTypeForm.name,
                doMain: true,
                level: this.equipTypeForm.level,

              }
              if (this.newOrEdit == 'editChild') {
                data.parentId = this.rowId;
              }
              if (value == 'commit') {
                data.submitType = this.submitType.submitOpen
              } else if (value == 'save') {
                data.submitType = this.submitType.submitDraft
              }
            } else if (this.newOrEdit == 'newChild') {

              var url = '/technology/addEquipmentType.htm';
              var data = {
                parentId: this.rowId,
                name: this.equipTypeForm.name,
                status: 2,
                level: 2,
                doMain: true,
              };
              if (value == 'commit') {
                data.submitType = this.submitType.submitOpen
              } else if (value == 'save') {
                data.submitType = this.submitType.submitDraft
              }

            }
            this.isRepeat = false;
            this.$http({
              method: 'post',
              apiUrl: url,
              params: data,
              isJson: true,
            }).then(res => {
              this.isRepeat = true;
              if (res.code == 0) {
                this.$message({
                  type: 'success',
                  message: '提交成功!'
                });
                this.close('equipTypeForm');

                if (this.newOrEdit == 'new' || this.newOrEdit == 'edit') {
                  this.readEquipmentType();
                } else {
                  this.showEquipType({ id: this.rowId }, { label: '类型' })
                }


              }

            }).catch(() => {

            });

          } else {
            return false;
          }
        })
      },
      //删除仪器类型
      deleteEquipType(row, isParent) {
        this.$confirm('是否删除', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          if (isParent == 'check') {
            var url = '/technology/deleteUsecheck.htm'
          } else if (isParent == 'tenance') {
            var url = '/technology/deleteMaintenance.htm'
          } else {
            var url = '/technology/delEquipmentType.htm'
          }
          this.$http({
            method: 'post',
            apiUrl: url,
            params: {
              id: row.id,
            },
            isJson: false,
          }).then(res => {
            if (res.code === 0) {
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
              if (isParent == 'parent') {

                this.readEquipmentType();
                this.rowId = ''
              } else if (isParent == 'child') {
                this.showEquipType({ id: this.rowId }, { label: '类型' })
                this.childRowId = ''
              } else {
                this.showCheckTenance({ id: this.childRowId }, { label: '类别' })
              }
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      //启用或者停用方法
      isStart(row, isParent) {
        var msg = row.status == 0 ? "启用" : "停用";
        this.$confirm("是否" + msg, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            method: 'post',
            apiUrl: '/technology/updateEquipmentTypeStatus.htm',
            params: {
              id: row.id,
              status: row.status == 0 ? 1 : 0,
            },
            isJson: false,
          }).then(res => {
            if (res.code === 0) {
              if (isParent != 'child') {
                this.readEquipmentType();
              } else {
                this.showEquipType({ id: this.rowId }, { label: '类型' })
              }


            }

          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消' + msg
          });
        });
      },
      // 点击二级仪器类型 显示维修项 检查项
      showCheckTenance(row, column, event) {
        for (var i in row) {
          this.checkChildRow[i] = row[i]
        }
        this.childRowId = row.id;
        // if (column.label != '操作') {
          this.eqDetailShow = true;
          var data = {
            id: row.id,
          }
          this.$http({
            method: 'post',
            apiUrl: '/technology/readMaintenanceList.htm',
            params: data,
            isJson: false,
          }).then(res => {
            if (res.code === 0) {
              this.maintainRecordTableDate = res.data;
              // this.reLoad();

            }

          })
          this.$http({
            method: 'post',
            apiUrl: '/technology/readUsecheckList.htm',
            params: data,
            isJson: false,
          }).then(res => {
            if (res.code === 0) {
              this.checkList = res.data;
              //  this.eqDetailShow = true;
            }

          })
        // }
      },
      addcheck(status) {
        if (this.childRowId == "") {
          this.$message({
            type: 'info',
            message: '请先选中仪器类别！',
          })
        } else {
          this.lookOrNew = "新增"
          this.canEdit = true;
          this.checkItemVisible = true;
          this.checkStatus = status;
        }

      },
      subCheck(checkForm) {
        this.$refs.checkForm.validate((valid) => { //表单验证
          if (valid) {
            if (this.checkStatus == 'tenance') {
              var url = '/technology/addMaintenance.htm';
              var data = {
                fRef: this.childRowId,
                content: this.checkForm.content,
                name: this.checkForm.name,
                checkType: this.checkForm.checkType,
              }
            } else {
              var url = '/technology/addUsecheck.htm';
              var data = {
                fRef: this.childRowId,
                content: this.checkForm.content,
                name: this.checkForm.name,
                checkType: this.checkForm.checkType1,
              }
            }
            this.isRepeat = false;
            this.$http({
              method: 'post',
              apiUrl: url,
              params: data,
              isJson: true,
            }).then(res => {
              this.isRepeat = true;
              if (res.code == 0) {
                this.$message({
                  type: 'success',
                  message: '提交成功!'
                });
                this.showCheckTenance({ id: this.childRowId }, { label: '类别' })

                this.closeCheck('checkForm');
              }

            }).catch(() => {

            });

          } else {
            return false;
          }
        })
      },
      editCheck(row, checkOrTenance) {
        this.checkItemVisible = true;
        this.lookOrNew = "查看";
        this.canEdit = false;
        if (checkOrTenance == 'check') {
          for (var i in row) {
            if (i == 'checkType') {
              console.log(row[i])
              this.checkForm.checkType1 = row[i]
            }
            this.checkForm[i] = row[i];
          }
        } else {
          for (var i in row) {
            this.checkForm[i] = row[i];
          }
        }
        if (this.checkForm.createTime != undefined) {
          this.checkForm.createTime = this.checkForm.createTime.slice(0, this.checkForm.createTime.indexOf("."));
        }
        if (this.checkForm.updateTime != undefined) {
          this.checkForm.updateTime = this.checkForm.updateTime.slice(0, this.checkForm.updateTime.indexOf("."));
        }

      },
      closeCheck(formName) {
        this.$refs[formName].resetFields();
        this.checkItemVisible = false;
        this.isRepeat = true;
        this.checkForm = {
          checkType: "MA01",
          checkType1: '',

        };

      },
      changeStatus(row) {

      }
    }

  }

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .separaterow {
    margin-top: 0px;
  }

  .equipStadndar .searchInput {
    vertical-align: top;
    width: calc(100% / 4);
  }

  .equipStadndar .searchIcon {
    margin-left: 20px;
  }

  .equipStadndar .separaterow {
    height: 100%;
    background: #fff;
    padding: 0 20px;
  }

  .equipStadndar .separaterow .tableCon {
    height: calc(100% - 46px)
  }
</style>
<style>
  .equipTypeForm .el-select,
  .equipChildForm .el-select {
    width: 100%;
  }

  .equipTypeForm.equipDialog .el-dialog {
    height: 70%;
  }
  .equipTypeForm.equipDialog .el-tabs__content{
    height:calc(100% - 50px);
  }

  .tabChange .tabName {
    width: 80px;
    height: 28px;
    line-height: 28px;
    background-color: #ffffff;
    border-radius: 0px 2px 2px 0px;
    text-align: center;
    border: solid 1px #cccccc;
    display: inline-block;
    cursor: pointer;
    color: #b3b3b3;
    padding: 0 !important;
  }

  .tabChange .tabName:nth-of-type(1) {
    border-right: none;
  }

  .tabChange .tabName:nth-of-type(2) {
    border-left: solid 1px #409eff;
  }

  .tabChange .activeTab {
    color: #409eff;
    border-color: #409eff;
  }

  .tabChange .infoitem {
    width: calc(100%/2);
    padding-right: 20px;
  }

  .tabChange .informationItem {
    width: calc(100% - 113px);
    float: right;
  }

  .tabChange .separaterow {
    height: 100%;
    background: #fff;
    padding: 0 15px;
  }

  .tabChange .separaterow .tableCon {
    height: calc(100% - 46px)
  }

  .tabChange .basicRightDistanceA {
    position: absolute;
    top: -78px;
    right: 0px
  }

  .tabChange .childTable {
    margin-top: 10px;
    height: 100%;
  }
</style>